from selenium.webdriver.common.by import By

from base.page_base import PageBase


class CartPage(PageBase):
    """购物车页面"""
    # 定位元素
    __goods_name = (By.ID, 'com.netease.yanxuan:id/tv_goods_name')
    __add = (By.XPATH, '//*[@text="加入购物车"]')
    __sure = (By.XPATH, '//android.widget.TextView[@resource-id="com.netease.yanxuan:id/button"]')
    __success_res = (By.XPATH, '//android.widget.Toast[@text="加入购物车成功"]')
    # 返回首页
    __back1 = (By.ID, 'com.netease.yanxuan:id/nav_left_text')
    __back2 = (By.ID, 'com.netease.yanxuan:id/search_bar_return')
    def click_goods_name(self):
        """点击商品名称"""
        self.base_click(self.__goods_name)
    def click_add(self):
        """点击加入购物车"""
        self.base_click(self.__add)

    def click_sure(self):
        """点击确定"""
        self.base_click(self.__sure)
    def get_success_res(self):
        """获取成功提示"""
        return self.base_get_toast(self.__success_res)
    def back1(self):
        """返回首页"""
        self.base_click(self.__back1)
    def back2(self):
        """返回购物车"""
        self.base_click(self.__back2)

    def add_cart(self):
        """加入购物车"""
        self.click_goods_name()
        self.click_add()
        self.click_sure()

    def back_home(self):
        """返回首页"""
        self.base_click(self.__back1)
        self.base_click(self.__back2)
        self.base_click(self.__back2)
